package com.aduerr.v1shouyin.mvp.activity;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.aduerr.v1shouyin.R;
import com.aduerr.v1shouyin.mvp.fragment.AdvanceFilterFregment;
import com.aduerr.v1shouyin.mvp.fragment.OrderNumFiltrateFregment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

/**
 * 订单筛选页面
 */

public class OrderFiltrateActivity extends AppCompatActivity {

    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.tb_inflet)
    TabLayout tbInflet;
    @BindView(R.id.vp_inflet)
    ViewPager vpInflet;
    private ArrayList<Fragment> fragments;
    private Mypager mypager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_filtrate);
        ButterKnife.bind(this);
        initUI();
    }

    private void initUI() {
        tvTitle.setText("订单筛选");
        fragments = new ArrayList<>();
        fragments.add(new OrderNumFiltrateFregment());
        fragments.add(new AdvanceFilterFregment());
        mypager = new Mypager(getSupportFragmentManager());

        vpInflet.setAdapter(mypager);
        //联动
        tbInflet.setupWithViewPager(vpInflet);
        vpInflet.setOffscreenPageLimit(1);

    }

    @OnClick(R.id.img_back)
    public void onViewClicked() {
        finish();
    }

    class Mypager extends FragmentPagerAdapter {
        ArrayList<String> titles = new ArrayList<>();

        public Mypager(FragmentManager fm) {
            super(fm);
            titles.add("订单号筛选");
            titles.add("高级筛选");
        }

        @Override
        public int getCount() {
            return titles != null ? titles.size() : 0;
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles.get(position);
        }

    }
}
